package com.richpencil.sqlsearch;

import com.richpencil.utils.StringHelper;
import lombok.Data;

import org.springframework.util.StringUtils;

@Data
public class SQLStatementItem {

    public SQLStatement sqlStatement=null;
    public String beforeOp="";
    public String fieldname="";
    public String afterOp="";
    public String fieldvalue="";
    public String paramname="";
    public String oldparamname="";
    public String SQL(String value)
    {
        String tmpParamvariable= StringUtils.replace(fieldvalue, "${"+paramname+"}", value);
        StringBuilder b=new StringBuilder();
        b.append(" "+this.beforeOp+" ");
        b.append(this.fieldname+" ");
        b.append(this.afterOp+" ");
        b.append(     tmpParamvariable+" ");
        return b.toString();
    }
    public String SQL(Object value)
    {
        String stringv="";
        if(!StringHelper.IsEmptyOrNull(value))
        {
            stringv=value.toString();
        }
        String tapParameterizable=StringUtils.replace(fieldvalue, "${"+paramname+"}", stringv);
        StringBuilder b=new StringBuilder();
        if(this.sqlStatement.getFissearch()=="1") {
            if(!StringHelper.IsEmptyOrNull(value)) {
                b.append(" "+this.beforeOp+" ");
                b.append(this.fieldname+" ");
                b.append(this.afterOp+" ");
                b.append(     tapParameterizable+" ");
                return b.toString();
            }
        } else {
            b.append(" "+this.beforeOp+" ");
            b.append(this.fieldname+" ");
            b.append(this.afterOp+" ");
            b.append(     tapParameterizable+" ");
            return b.toString();
        }
        return "";
    }
}